package com.example.mybatisplus.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mybatisplus.model.domain.Division;
import com.example.mybatisplus.mapper.DivisionMapper;
import com.example.mybatisplus.model.dto.PageDTO;
import com.example.mybatisplus.service.DivisionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author lxp
 * @since 2023-01-01
 */
@Service
public class DivisionServiceImpl extends ServiceImpl<DivisionMapper, Division> implements DivisionService {

    @Autowired
    private DivisionMapper divisionMapper;

    @Override
    public Page<Division> pageList(Division division, PageDTO pageDTO) {
//      分页器
        Page<Division> page = new Page<>(pageDTO.getPageNo(),pageDTO.getPageSize());
//      条件构造器
        QueryWrapper<Division> wrapper = new QueryWrapper<>();
//      差一个条件构造器
        if (division.getDivision() != null){
            wrapper.like("division", division.getDivision());
        }
        Page<Division> divisionPage = divisionMapper.selectPage(page, wrapper);
        return divisionPage;
//        @Override
//        public Page<Division> pageList(Division division, PageDTO pageDTO) {
////      分页器
//            Page<Division> page = new Page<>(pageDTO.getPageNo(),pageDTO.getPageSize());
////      条件构造器
//            QueryWrapper<Division> wrapper = new QueryWrapper<>();
////      差一个条件构造器
//            if (division.getDivision() != null){
//                wrapper.like("division", division.getDivision());
//            }
//            Page<Division> divisionPage = divisionMapper.selectPage(page, wrapper);
//            return divisionPage;
//        }
    }
}
